package app.kernel.results;

import java.util.Hashtable;
import java.util.Vector;

// Written by: Ng Wen Long
// For mapping requests to consolidated results 
public class DataRequestTable {
	
	Hashtable LookupRequestTable = new Hashtable();
	Hashtable Lookup_CP_RequestTable = new Hashtable();
	Hashtable SubscriptionRequestTable = new Hashtable();
	
	public DataRequestTable(){
		
		
	}
	
	public void addLookupRequest(String qSignature){
		
		System.out.println("Add Lookup********"+qSignature+"********");
		LookupRequestTable.put(qSignature, new QueryResult(qSignature, null));
		
	}
	

	public void addLookupCP_Request(String qSignature){
		
		//System.out.println("Add Lookup Coordinator ********"+qSignature+"********");
		Lookup_CP_RequestTable.put(qSignature, new QueryResult(qSignature, null));
		
	}
	
	// Called by reporting PSGs.
	public void reportResultsToLookupRequest(String qSignature, String result){
		
		QueryResult getRes = (QueryResult)LookupRequestTable.get(qSignature);
		System.out.println("Report Lookup********"+qSignature+"********");
		System.out.println("Result = "+result);
		
		getRes.addResult(result);
		System.out.println(getRes.toString());
		LookupRequestTable.put(qSignature, getRes);
		
	}

	// Called by reporting CP.
	public void reportResultsToLookup_CP_Request(String qSignature, String result){
		
		QueryResult getRes = (QueryResult)Lookup_CP_RequestTable.get(qSignature);
		System.out.println("Report Coordinator Lookup********"+qSignature+"********");
		System.out.println("Result = "+result);
		
		getRes.addResult(result);
		System.out.println(getRes.toString());
		Lookup_CP_RequestTable.put(qSignature, getRes);
		
		
	}
	
	public QueryResult getResults(String qSignature){
		
		return (QueryResult) LookupRequestTable.get(qSignature);
		
	}

	public QueryResult getCPResults(String qSignature){
		
		return (QueryResult) Lookup_CP_RequestTable.get(qSignature);
		
	}
	
	public void addSubscriptionRequest(String qSignature){
		
		SubscriptionRequestTable.put(qSignature, new QueryResult(qSignature, null));
		
	}
	
	// Called by reporting PSGs.
	public void reportResultsToSubscriptionRequest(String qSignature, String result){
		
		QueryResult getRes = (QueryResult)SubscriptionRequestTable.get(qSignature);
		getRes.addResult(result);		
		SubscriptionRequestTable.put(qSignature, getRes);
		
	}
	
	

	

}
